/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.bid.service.plugins  
 */
package com.apache.bid.service.plugins;

import java.util.List;

import org.apache.log4j.Logger;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.bid.common.WbdToolsUtil;
import com.apache.bid.entity.BidInfoBaojia;
import com.apache.cache.util.Validator;
import com.apache.database.db.IDao;
import com.apache.database.model.MethodParam;
import com.apache.database.model.Page;

/**
 * description:  查询报价记录
 * @author mhguo 创建时间：2016-4-12  
 * 
 */
public class BidInfoBaojiaListPlugin implements PluginConnector {
	private IDao bidInfoBaojiaDao;
	private Logger logger = Logger.getLogger(BidInfoBaojiaListPlugin.class);

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.zbxsoft.api.manager.PluginConnector#execute(com.zbxsoft.api.vo.ParamsVo)  
	 */
	@Override
	public Object execute(ParamsVo vo) throws Exception {
		ResultEntity result = new ResultEntity();
		try {
			result.setResult("true");
			//单独处理的特殊参数情况[暂无]
			//-------------------
			MethodParam param = setMethodParams(vo, 2, "");
			if (Validator.isEmpty(param)) {
				result.setResult("false");
				result.setMessage("查询条件为空!");
				return result;
			}
			int pageSize = Integer.valueOf(Validator.getDefaultStr(String.valueOf(vo.getParams("pageSize")), "0"));
			int pageIndex = Integer.valueOf(Validator.getDefaultStr(String.valueOf(vo.getParams("pageIndex")), "0"));
			param.setResultCache(false);
			if (pageSize == 0 && pageIndex == 0) {
				List list = bidInfoBaojiaDao.select(param);
				result.setEntity(list);
			} else {
				param.setPageIndex(pageIndex);
				param.setPageSize(pageSize);
				Page page = bidInfoBaojiaDao.pageSelect(param);
				result.setEntity(page);
			}
		} catch (Exception e) {
			result.setResult("false");
			logger.error("执行Baojia列表查询失败 ", e);
			result.setMessage("Baojia列表查询失败！");
		}
		return result;
	}

	private MethodParam setMethodParams(ParamsVo vo, int type, String orderBy) {
		MethodParam param = new MethodParam("ByProperty", "", "", BidInfoBaojia.class.getName());
		param.setResultCache(false);
		String all = String.valueOf(vo.getParams("bidInfoBaojiaAll"));//获取所有活动列表
		if (Validator.isNull(all)) {
			getBidInfoBaojiaParams(param, vo);
			if (Validator.isEmpty(param.getParams()) || param.getParams().size() == 0)
				return null;
		}
		return param;
	}

	//组织BidInfoBaojia信息查询条件
	private void getBidInfoBaojiaParams(MethodParam param, ParamsVo vo) {
		BidInfoBaojia bidInfoBaojia = new BidInfoBaojia();
		bidInfoBaojia = (BidInfoBaojia) WbdToolsUtil.getInstance().convert2Bean(vo.getParams(), bidInfoBaojia);
		if (Validator.isNotNull(bidInfoBaojia.getItemId())) {
			param.setParams("itemId", bidInfoBaojia.getItemId());
		}
		if (Validator.isNotNull(bidInfoBaojia.getBidValue())) {
			param.setParams("bidValue", bidInfoBaojia.getBidValue());
		}
		if (Validator.isNotNull(bidInfoBaojia.getBidTime())) {
			param.setParams("bidTime", bidInfoBaojia.getBidTime());
		}
		if (Validator.isNotNull(bidInfoBaojia.getBidNum())) {
			param.setParams("bidNum", bidInfoBaojia.getBidNum());
		}
		if (Validator.isNotNull(bidInfoBaojia.getAmount())) {
			param.setParams("amount", bidInfoBaojia.getAmount());
		}
		if (Validator.isNotNull(bidInfoBaojia.getUserId())) {
			param.setParams("userId", bidInfoBaojia.getUserId());
		}
		if (Validator.isNotNull(bidInfoBaojia.getUserName())) {
			param.setParams("userName", bidInfoBaojia.getUserName());
		}
		if (Validator.isNotNull(bidInfoBaojia.getRightLevel())) {
			param.setParams("rightLevel", bidInfoBaojia.getRightLevel());
		}
		if (Validator.isNotNull(bidInfoBaojia.getUserIp())) {
			param.setParams("userIp", bidInfoBaojia.getUserIp());
		}
		if (Validator.isNotNull(bidInfoBaojia.getIncValue())) {
			param.setParams("incValue", bidInfoBaojia.getIncValue());
		}
		if (Validator.isNotNull(bidInfoBaojia.getTurn())) {
			param.setParams("turn", bidInfoBaojia.getTurn());
		}
		if (Validator.isNotNull(bidInfoBaojia.getBidType())) {
			param.setParams("bidType", bidInfoBaojia.getBidType());
		}
		if (Validator.isNotNull(bidInfoBaojia.getWeight())) {
			param.setParams("weight", bidInfoBaojia.getWeight());
		}
		if (Validator.isNotNull(bidInfoBaojia.getBidUserNo())) {
			param.setParams("bidUserNo", bidInfoBaojia.getBidUserNo());
		}
		if (Validator.isNotNull(bidInfoBaojia.getUpdateTimes())) {
			param.setParams("updateTimes", bidInfoBaojia.getUpdateTimes());
		}
	}

	public void setBidInfoBaojiaDao(IDao bidInfoBaojiaDao) {
		this.bidInfoBaojiaDao = bidInfoBaojiaDao;
	}

}
